package com.canaan.business.controller.pc.invoice;

import com.canaan.business.domain.invoice.WmsProStockApply;
import com.canaan.business.domain.vo.WmsProStockApplyVo;
import com.canaan.business.service.invoice.IWmsProStockApplyService;
import com.canaan.common.annotation.Log;
import com.canaan.common.core.controller.BaseController;
import com.canaan.common.core.domain.AjaxResult;
import com.canaan.common.core.page.TableDataInfo;
import com.canaan.common.enums.BusinessType;
import com.canaan.common.exception.ServiceException;
import com.canaan.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产入库申请单Controller
 *
 * @author ruoyi
 * @date 2022-12-19
 */
@Api(tags = "生产入库申请单")
@RestController
@RequestMapping("/invoice/proStockApply")
public class WmsProStockApplyController extends BaseController
{
    @Resource
    private IWmsProStockApplyService wmsProStockApplyService;

    /**
     * 查询生产入库申请单列表
     */
    @ApiOperation(value = "查询生产入库申请单列表")
    @GetMapping("/list")
    public TableDataInfo list(WmsProStockApply wmsProStockApply)
    {
        startPage();
        List<WmsProStockApply> list = wmsProStockApplyService.selectWmsProStockApplyList(wmsProStockApply);
        return getDataTable(list);
    }

    /**
     * 导出生产入库申请单列表
     */
    @ApiOperation(value = "导出生产入库申请单列表")
    @Log(title = "生产入库申请单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsProStockApply wmsProStockApply)
    {
        List<WmsProStockApplyVo> list = wmsProStockApplyService.exportList(wmsProStockApply);
        ExcelUtil<WmsProStockApplyVo> util = new ExcelUtil<WmsProStockApplyVo>(WmsProStockApplyVo.class);
        util.exportExcel(response, list, "生产入库申请单数据");
    }

    /**
     * 获取生产入库申请单详细信息
     */
    @ApiOperation(value = "获取生产入库申请单详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wmsProStockApplyService.selectWmsProStockApplyById(id));
    }

    /**
     * 新增生产入库申请单
     */
    @ApiOperation(value = "新增生产入库申请单")
    @Log(title = "生产入库申请单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmsProStockApply wmsProStockApply)
    {
        return toAjax(wmsProStockApplyService.insertWmsProStockApply(wmsProStockApply));
    }

    /**
     * 修改生产入库申请单
     */
    @Log(title = "生产入库申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改生产入库申请单")
    public AjaxResult edit(@RequestBody WmsProStockApply wmsProStockApply)
    {
        return toAjax(wmsProStockApplyService.updateWmsProStockApply(wmsProStockApply));
    }

    /**
     * 删除生产入库申请单
     */
    @ApiOperation(value = "删除生产入库申请单")
    @Log(title = "生产入库申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsProStockApplyService.deleteWmsProStockApplyByIds(ids));
    }


    /**
     * 订单取消
     */
    @ApiOperation(value = "订单取消")
    @Log(title = "订单取消", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel")
    public AjaxResult cancel(@RequestBody List<Long> ids) {
        return success(wmsProStockApplyService.cancel(ids));
    }

    /**
     * 订单确认取消
     */
    @ApiOperation(value = "订单确认取消")
    @Log(title = "订单取消", businessType = BusinessType.UPDATE)
    @PutMapping("/confirmCancel")
    public AjaxResult cancel(@RequestBody WmsProStockApply wmsProStockApply) {
        if(wmsProStockApply == null || wmsProStockApply.getId() == null){
            throw new ServiceException("缺少必要参数");
        }
        return success(wmsProStockApplyService.confirmCancel(wmsProStockApply));
    }
}
